{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# sql_magic API"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Load extension"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:35.246267Z",
     "start_time": "2017-04-12T12:36:27.118134-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "\n",
       "    require(['notebook/js/codecell'], function(codecell) {\n",
       "      // https://github.com/jupyter/notebook/issues/2453\n",
       "      codecell.CodeCell.options_default.highlight_modes['magic_text/x-sql'] = {'reg':[/^%read_sql/, /.*=\\s*%read_sql/,\n",
       "                                                                                      /^%%read_sql/]};\n",
       "      Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n",
       "          console.log('BBBBB');\n",
       "          Jupyter.notebook.get_cells().map(function(cell){\n",
       "              if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n",
       "      });\n",
       "    });\n",
       "    "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%load_ext sql_magic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Use sql_magic with a psycopg2 connection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:39.729531Z",
     "start_time": "2017-04-12T12:36:39.637184-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cursor object at 0x10f46a520; closed: 0>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas.io.sql as psql\n",
    "import psycopg2\n",
    "connect_credentials = {'database': 'postgres',\n",
    "                       'host': 'localhost',\n",
    "                       'password': '',\n",
    "                       'user': 'postgres'}\n",
    "\n",
    "# connect to postgres connection object\n",
    "conn = psycopg2.connect(**connect_credentials)\n",
    "conn.autocommit = True\n",
    "schema_name = 'template'\n",
    "psql.execute('SET search_path TO {}'.format(schema_name), conn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:39.762823Z",
     "start_time": "2017-04-12T12:36:39.731487-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "%config SQL.conn_name='conn'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:39.794579Z",
     "start_time": "2017-04-12T12:36:39.764497-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:56 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>version</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>PostgreSQL 9.6.1 on x86_64-apple-darwin14.5.0,...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             version\n",
       "0  PostgreSQL 9.6.1 on x86_64-apple-darwin14.5.0,..."
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql\n",
    "SELECT version()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### Assign result to pandas dataframe and plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:49.129002Z",
     "start_time": "2017-04-12T12:36:49.070658-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:56 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>s</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    s\n",
       "0   1\n",
       "1   2\n",
       "2   3\n",
       "3   4\n",
       "4   5\n",
       "5   6\n",
       "6   7\n",
       "7   8\n",
       "8   9\n",
       "9  10"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql df\n",
    "SELECT generate_series(1,10,1) s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:52.291526Z",
     "start_time": "2017-04-12T12:36:50.549670-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x10ffd0438>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgAAAAFkCAYAAABW9YMrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAH0hJREFUeJzt3X2QZXV95/H3F2UdR2KTclbEwKy4EByLSeNtwsMasLIg\nZKlCJaXRK6hIAMeopZ11QZ5kwDViO4rxidpUXAchXkstWbUWFR+STVBGeroFH2hEBRwVJA4mjTLY\nKvPbP84F7jTz0H3vOfc83PerqqtyD33O73sy45zf5/s795xIKSFJkkbLXmUXIEmShs8JgCRJI8gJ\ngCRJI8gJgCRJI8gJgCRJI8gJgCRJI8gJgCRJI8gJgCRJI8gJgCRJI8gJgCRJI2jZE4CIODYiPhsR\nP42I7RHxgp38zmURcXdEbIuIL0XEwfmUK0mS8tBPB+BJwM3AXwGPeZFARJwHvB44BzgSeAD4YkT8\nhwHqlCRJOYpBXgYUEduBF6WUPtuz7W7gXSmlK7qfnwzcC7wqpfSJAeuVJEk5yPUegIg4CHga8JWH\nt6WU7ge+ARyT51iSJKl/j8/5eE8jWxa4d9H2e7v/7TEi4inAScBdwK9zrkeSpCZbATwD+GJK6b7l\n7Jj3BKAfJwH/UHYRkiTV2GnAx5azQ94TgJ8BAezHjl2A/YBv7mKfuwCuueYa1qxZk3M55ZicnOSK\nK64ou4zcNOl8mnQu4PlUWZPOBTyfKvnNb+Dv/g6uugpWr57jrrtOh+61dDlynQC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3HLmEeStbVqLMzyVrMdV0vh+y+n4cWbdtOBb4OP6iU0oPdi//vk3375P8sZb+ylwDeA2yMiBng\nJmCS7A9pY5lF9aNJL0GKiA8BbeAFwAMR8XCXZj6lVLtXNkfE3wCfB7YAv0d2I9PzgBPLrKsf3XXx\nHe7FiIgHgPtSSouTZ+VFxLuAz5FdIP8AuBT4LdAps64BXAF8LSLOJ/uq3FHAWcDZu92rwrrB7Axg\nY0ppe8nlDOJzwEUR8RPgu2RfC54E/r7UqgYQESeSXXO+BxxC1uW4lSVeQ0udAKSUPtH9itllZK3/\nm4GTUko/L7OuPh3Boy9BSmQ3AUF2w0zdXoK0juwc/mnR9lcDHx16NYN7Ktmfw/7APPAt4MSG3EEP\n9X7uxAFka5ZPAX4O3AAcnVK6r9Sq+pRS2hwRp5LdcHYxcCfwxrreaNZ1AnAg9bwno9frgbeRfYPm\nqcDdwJXdbXU1BryDbPL8C+BTwEUppcWdjp3yZUCSJI2g2q99SJKk5XMCIEnSCHICIEnSCHICIEnS\nCHICIEnSCHICIEnSCHICIEnSCHICIEnSCHICIEnSCHICIEnSCHICIEnSCPr/QDPyV5baOrUAAAAA\nSUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10f4d1588>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "df.plot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### Utilize Python variables in SQL query"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:56.140155Z",
     "start_time": "2017-04-12T12:36:56.117434-04:00"
    },
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "lower, upper = 9,15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:56.510477Z",
     "start_time": "2017-04-12T12:36:56.453756-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:56 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>s</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    s\n",
       "0   9\n",
       "1  11\n",
       "2  13\n",
       "3  15"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql df\n",
    "SELECT *\n",
    "FROM (SELECT generate_series(1,20,2) s) f\n",
    "WHERE s BETWEEN {lower} and {upper}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Connect to Spark engine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:36.041212Z",
     "start_time": "2017-04-12T12:36:35.982503-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "%config SQL.conn_name='spark'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:39.635616Z",
     "start_time": "2017-04-12T12:36:36.702319-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:56 PM EDT; Query executed in 0.04 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   1\n",
       "0  1"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql\n",
    "SELECT 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Connect to postgres simulaneously"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:58 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>version</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>PostgreSQL 9.6.1 on x86_64-apple-darwin14.5.0,...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             version\n",
       "0  PostgreSQL 9.6.1 on x86_64-apple-darwin14.5.0,..."
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql -c conn\n",
    "SELECT version()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Use sql_magic with a SQLAlchemy Engine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:40.483096Z",
     "start_time": "2017-04-12T12:36:40.420883-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "# sqllite conn\n",
    "from sqlalchemy import create_engine\n",
    "from sqlite3 import dbapi2 as sqlite\n",
    "sqllite_engine = create_engine('sqlite+pysqlite:///test.db', module=sqlite)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:41.509536Z",
     "start_time": "2017-04-12T12:36:41.477245-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "%config SQL.conn_name='sqllite_engine'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:41.990698Z",
     "start_time": "2017-04-12T12:36:41.957830-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:59 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sqlite_version()</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.13.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  sqlite_version()\n",
       "0           3.13.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql\n",
    "SELECT sqlite_version();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Miscelleanous results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-12T16:36:46.562578Z",
     "start_time": "2017-04-12T12:36:46.528083-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:59 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<sql_magic.exceptions.EmptyResult at 0x1134bae10>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql\n",
    "DROP TABLE IF EXISTS example_table;\n",
    "CREATE TEMP TABLE example_table\n",
    "AS\n",
    "SELECT 1;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:59 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   1\n",
       "0  1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql\n",
    "SELECT 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Asynchronous calls\n",
    "Queries can be run in async mode using the --async (or -a) flag. Displaying results from async calls are disabled by default."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-11T15:16:48.833451Z",
     "start_time": "2017-04-11T11:16:48.812383-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:59 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<a id=\"1499899619\"></a>\n",
       "\n",
       "        <script>\n",
       "        function notifyMe() {\n",
       "          if (Notification.permission !== \"granted\")\n",
       "            Notification.requestPermission();\n",
       "          else {\n",
       "            var notification = new Notification('Query Finished in 0.00 m', {\n",
       "              icon: 'https://raw.githubusercontent.com/crawles/Logos/master/jupyter.png?raw=true',\n",
       "              body: \"Name: df\\nDimensions: (1, 1)\",\n",
       "            });\n",
       "\n",
       "            notification.onclick = function () {\n",
       "              document.getElementById('1499899619').scrollIntoView();\n",
       "            };\n",
       "\n",
       "          }\n",
       "        }\n",
       "        var isIE = /*@cc_on!@*/false || !!document.documentMode;\n",
       "        // prevents notifications from popping up when notebook is re-opened\n",
       "        if (Date.now() < 1499899620103.2158 && !isIE) {\n",
       "        notifyMe(); };\n",
       "        </script>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql df -a\n",
    "SELECT 'long query here'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# Configuration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Flags\n",
    "Notifications and auto-display can be temporarily disabled with flags:\n",
    "<pre>\n",
    "positional arguments:\n",
    "  table_name\n",
    "\n",
    "optional arguments:\n",
    "  -h, --help     show this help message and exit\n",
    "  -n, --notify   Toggle option for notifying query result\n",
    "  -a, --async    Run query in seperate thread. Please be cautious when\n",
    "                 assigning result to a variable\n",
    "  -d, --display  Toggle option for outputing query result\n",
    "</pre>\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-11T14:27:38.836704Z",
     "start_time": "2017-04-11T10:27:38.798277-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:59 PM EDT; Query executed in 0.00 m"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   1\n",
       "0  1"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%read_sql\n",
    "SELECT 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-11T14:27:38.866000Z",
     "start_time": "2017-04-11T10:27:38.838645-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:59 PM EDT; Query executed in 0.00 m"
     ]
    }
   ],
   "source": [
    "%%read_sql -d\n",
    "SELECT 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Defaults\n",
    "Notifications and displaying results are enabled by default, but can be turned off with %config magic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-11T14:27:38.897993Z",
     "start_time": "2017-04-11T10:27:38.867451-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SQL options\n",
      "---------\n",
      "SQL.conn_name=<Unicode>\n",
      "    Current: 'sqllite_engine'\n",
      "    Object name for accessing computing resource environment\n",
      "SQL.notify_result=<Bool>\n",
      "    Current: True\n",
      "    Notify query result to stdout\n",
      "SQL.output_result=<Bool>\n",
      "    Current: True\n",
      "    Output query result to stdout\n"
     ]
    }
   ],
   "source": [
    "# alerts and display are automatically enabled\n",
    "%config SQL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-11T14:27:38.933933Z",
     "start_time": "2017-04-11T10:27:38.899885-04:00"
    },
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "%config SQL.output_result = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-04-11T14:27:38.967276Z",
     "start_time": "2017-04-11T10:27:38.935601-04:00"
    },
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query started at 06:46:59 PM EDT; Query executed in 0.00 m"
     ]
    }
   ],
   "source": [
    "%%read_sql\n",
    "SELECT 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "_draft": {
   "nbviewer_url": "https://gist.github.com/a6a28649c4299546aa970d2efbbbce59"
  },
  "anaconda-cloud": {},
  "gist": {
   "data": {
    "description": "test_thread_html",
    "public": true
   },
   "id": "a6a28649c4299546aa970d2efbbbce59"
  },
  "kernelspec": {
   "display_name": "Python [py3k]",
   "language": "python",
   "name": "Python [py3k]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "nav_menu": {},
  "toc": {
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 6,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
